package demoMod.invincibleOne.cards.invincible;

import com.megacrit.cardcrawl.actions.AbstractGameAction;
import com.megacrit.cardcrawl.actions.common.ApplyPowerAction;
import com.megacrit.cardcrawl.actions.common.DamageAction;
import com.megacrit.cardcrawl.actions.common.GainBlockAction;
import com.megacrit.cardcrawl.actions.watcher.ChangeStanceAction;
import com.megacrit.cardcrawl.cards.DamageInfo;
import com.megacrit.cardcrawl.cards.purple.TalkToTheHand;
import com.megacrit.cardcrawl.characters.AbstractPlayer;
import com.megacrit.cardcrawl.core.CardCrawlGame;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
import com.megacrit.cardcrawl.localization.CardStrings;
import com.megacrit.cardcrawl.monsters.AbstractMonster;
import com.megacrit.cardcrawl.powers.watcher.BlockReturnPower;
import com.megacrit.cardcrawl.powers.watcher.MentalFortressPower;
import com.megacrit.cardcrawl.powers.watcher.RushdownPower;
import com.megacrit.cardcrawl.stances.CalmStance;
import com.megacrit.cardcrawl.stances.WrathStance;
import demoMod.invincibleOne.InvincibleOneMod;

public class Rushdown extends AbstractInvincibleCard {
    public static final String ID = InvincibleOneMod.makeID("Rushdown");

    private static final CardStrings cardStrings = CardCrawlGame.languagePack.getCardStrings(ID);
    public static final String NAME = cardStrings.NAME;
    public static final String DESCRIPTION = cardStrings.DESCRIPTION;
    public static final String IMG_PATH = "cards/Rushdown.png";

    private static final CardType TYPE = CardType.POWER;
    private static final CardRarity RARITY = CardRarity.BASIC;
    private static final CardTarget TARGET = CardTarget.NONE;

    private static final int COST = 0;

    public Rushdown() {
        super(ID, NAME, InvincibleOneMod.getResourcePath(IMG_PATH), COST, DESCRIPTION, TYPE, RARITY, TARGET);
        playFirst = true;
        this.magicNumber = this.baseMagicNumber = 1;
        this.m2 = this.baseM2 = 1;
    }

    @Override
    public Runnable getUpgradeAction() {
        return () -> {
            this.rawDescription = cardStrings.UPGRADE_DESCRIPTION;
            this.initializeDescription();
            upgradeMagicNumber(1);
            this.m2 = this.baseM2 = 2;
        };
    }

    @Override
    public void use(AbstractPlayer p, AbstractMonster _m) {
        addToBot(new ApplyPowerAction(p, p, new RushdownPower(p, 1)));
        addToBot(new ApplyPowerAction(p, p, new MentalFortressPower(p, magicNumber)));
        for (AbstractMonster m : AbstractDungeon.getMonsters().monsters) {
            if (!m.isDeadOrEscaped()) {
                addToBot(new ApplyPowerAction(m, p, new BlockReturnPower(m, m2)));
            }
        }
        addToBot(new AbstractGameAction() {
            @Override
            public void update() {
                if (AbstractDungeon.player.stance.ID.equals(WrathStance.STANCE_ID)) {
                    addToBot(new ChangeStanceAction(CalmStance.STANCE_ID));
                } else {
                    addToBot(new ChangeStanceAction(WrathStance.STANCE_ID));
                }
                isDone = true;
            }
        });
    }
}
